
#ifndef BTNODE_H
#define BTNODE_H

#include<osg/Node>
#include<osg/Geode>
#include<osg/Geometry>
#include<osgText/Text>
#include<string>

enum NodeColor {BLACK, WHITE, RED, GREEN, BLUE};
enum BinaryTreeType {SIMPLE, REDBLACK};

/* Each node in the binary search tree is modeled as class 
 * BinaryTreeNode. */
class BinaryTreeNode
{
	private:
		double key;

		BinaryTreeNode * left;
		BinaryTreeNode * right;
		BinaryTreeNode * parent;

		/* Other satellite data. */
		int height;

		/* Scenegraph related fields. */
		float x;	/* X-coodinate of the center of the node. */
		float z;	/* Z-coodinate of the center of the node. */
		osg::Vec4 color_vec; // RGBA
		NodeColor color;

		osg::ref_ptr<osgText::Text> label;
		osg::ref_ptr<osg::Geometry> shape;

	public:

		BinaryTreeNode(double key_value);
		~BinaryTreeNode();

		static void left_rotate(BinaryTreeNode* & t, BinaryTreeNode * curr_node);
		static void right_rotate(BinaryTreeNode* & t, BinaryTreeNode * curr_node);

		static void insert(BinaryTreeNode* & t, BinaryTreeNode * curr_node);
		static void rb_insert(BinaryTreeNode* & t, BinaryTreeNode * nodez);
		static void rb_insert_fixup(BinaryTreeNode* & t, BinaryTreeNode * nodez);

		void tree_draw(osg::ref_ptr<osg::Geode>& geode);
		void draw(osg::ref_ptr<osg::Geode>& geode);

		void draw_label(osg::ref_ptr<osg::Geode>& geode);

		void set_color(NodeColor c) { color = c; }
		void apply_color();
		void tree_apply_color();
		void set_position(void);

		void print_tree();
};


#endif
